const app = getApp()

Page({
  data: {
    CustomBar: app.globalData.CustomBar,
    StatusBar: app.globalData.StatusBar,
    theme: app.globalData.theme, //全局颜色变量
    orderInfo: null,
    id: null,
    callPay: false,//是否直接调起支付
    opacity: 0,
  },
  onShow() {
    app.initPage()
      .then(res => {
        this.orderGet(this.data.id)
      })
  },
  onLoad(options) {
    this.setData({
      id: options.id
    })
    if (options.callPay){
      this.setData({
        callPay: true
      })
    }
  },
  orderGet(id){
    let that = this
    app.api.orderGet(id)
      .then(res => {
        let orderInfo = res.data
        if (!orderInfo){
          wx.redirectTo({
            url: '/pages/order/order-list/index'
          })
        }
        this.setData({
          orderInfo: orderInfo
        })
        setTimeout(function () {
          that.setData({
            callPay: false
          })
        }, 4000)
      })
  },
  //复制内容
  copyData(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.data
    })
  },
  orderCancel(){
    let id = this.data.orderInfo.id
    this.orderGet(id)
  },
  orderDel(){
    wx.navigateBack()
  },
  unifiedOrder() {
    this.onShow()
  },
  countDownDone(){
    this.orderGet(this.data.id)
  },
  toMap(){
    let expressSite = this.data.orderInfo.expressSite
    if(expressSite){
      wx.openLocation({
        longitude: Number.parseFloat(expressSite.longitude),
        latitude: Number.parseFloat(expressSite.latitude),
        name: expressSite.name
      })
    }
  },
  ViewImage(e) {
    wx.previewImage({
      urls: [e.currentTarget.dataset.url],
      current: e.currentTarget.dataset.url
    });
  },
  ViewImage3(e) {
    wx.previewImage({
      urls: this.data.orderInfo.goodsAppraises.picUrls,
      current: e.currentTarget.dataset.url
    });
  },
  BackPage() {
    wx.navigateBack({
      delta: 1
    });
  },
    /**
   * 监听用户滑动页面事件 计算顶部tabs透明度
   */
  onPageScroll(e) {
    let value = e.scrollTop / 100;
    value > 1 && (value = 1);
    this.setData({
      opacity: value
    })
  },
  handleContact() {
    wx.makePhoneCall({
      phoneNumber: this.data.orderInfo.providerVO.goodsCategorysDesc
    })
  }
})